##
## This file is part of the libsigrok project.
##
## Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
## Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##

ACLOCAL_AMFLAGS = -I m4
AM_LIBTOOLFLAGS = --silent
GNUMAKEFLAGS = --no-print-directory

# distutils/setuptools cause trouble on distcheck. Disable for now.
DISTCHECK_CONFIGURE_FLAGS = --disable-python

FIRMWARE_DIR = $(datadir)/sigrok-firmware

local_includes = -Iinclude -I$(srcdir)/include -I$(srcdir)/src -I. @RPC_CFLAGS@
if BINDINGS_CXX
local_includes += -Ibindings/cxx/include -I$(srcdir)/bindings/cxx/include -Ibindings/cxx
endif
# Do not hard-code the firmware location on Windows.
if WIN32
global_defs =
else
global_defs = -DFIRMWARE_DIR='"$(FIRMWARE_DIR)"'
endif
# Ensure that local include directories are always searched first.
AM_CPPFLAGS = $(local_includes) $(global_defs)

# The tests CFLAGS are a superset of the libsigrok CFLAGS, and the
# python bindings CFLAGS are a superset of the C++ bindings CFLAGS.
AM_CFLAGS = $(SR_EXTRA_CFLAGS) $(SR_WFLAGS) $(TESTS_CFLAGS)
AM_CXXFLAGS = $(SR_WXXFLAGS) $(LIBSIGROKCXX_CFLAGS)

lib_LTLIBRARIES = libsigrok.la

# Backend files
libsigrok_la_SOURCES = \
	src/backend.c \
	src/binary_helpers.c \
	src/conversion.c \
	src/crc.c \
	src/device.c \
	src/session.c \
	src/session_file.c \
	src/session_driver.c \
	src/hwdriver.c \
	src/trigger.c \
	src/soft-trigger.c \
	src/analog.c \
	src/fallback.c \
	src/resource.c \
	src/strutil.c \
	src/log.c \
	src/version.c \
	src/error.c \
	src/std.c \
	src/sw_limits.c

# Input modules
libsigrok_la_SOURCES += \
	src/input/input.c \
	src/input/feed_queue.c \
	src/input/binary.c \
	src/input/chronovu_la8.c \
	src/input/csv.c \
	src/input/logicport.c \
	src/input/raw_analog.c \
	src/input/saleae.c \
	src/input/trace32_ad.c \
	src/input/vcd.c \
	src/input/wav.c \
	src/input/null.c

# Output modules
libsigrok_la_SOURCES += \
	src/output/output.c \
	src/output/analog.c \
	src/output/ascii.c \
	src/output/bits.c \
	src/output/binary.c \
	src/output/csv.c \
	src/output/chronovu_la8.c \
	src/output/wav.c \
	src/output/hex.c \
	src/output/ols.c \
	src/output/srzip.c \
	src/output/vcd.c \
	src/output/wavedrom.c \
	src/output/null.c

# Transform modules
libsigrok_la_SOURCES += \
	src/transform/transform.c \
	src/transform/nop.c \
	src/transform/scale.c \
	src/transform/invert.c

# SCPI support
libsigrok_la_SOURCES += \
	src/scpi.h \
	src/scpi/scpi.c \
	src/scpi/scpi_tcp.c
if NEED_RPC
libsigrok_la_SOURCES += \
	src/scpi/scpi_vxi.c \
	src/scpi/vxi_clnt.c \
	src/scpi/vxi_xdr.c \
	src/scpi/vxi.h
endif
# if HAVE_BLUETOOTH
libsigrok_la_SOURCES += \
	src/bt/bt_bluez.c
# endif
if NEED_SERIAL
libsigrok_la_SOURCES += \
	src/serial.c \
	src/serial_bt.c \
	src/serial_hid.c \
	src/serial_hid.h \
	src/serial_hid_bu86x.c \
	src/serial_hid_ch9325.c \
	src/serial_hid_cp2110.c \
	src/serial_hid_victor.c \
	src/serial_libsp.c \
	src/scpi/scpi_serial.c
endif
if NEED_USB
libsigrok_la_SOURCES += \
	src/ezusb.c \
	src/usb.c \
	src/scpi/scpi_usbtmc_libusb.c
endif
if NEED_VISA
libsigrok_la_SOURCES += \
	src/scpi/scpi_visa.c
endif
if NEED_GPIB
libsigrok_la_SOURCES += \
	src/scpi/scpi_libgpib.c
endif

# Modbus support
libsigrok_la_SOURCES += \
	src/modbus/modbus.c
if NEED_SERIAL
libsigrok_la_SOURCES += \
	src/modbus/modbus_serial_rtu.c
endif

# Hardware (DMM chip parsers)
libsigrok_la_SOURCES += \
	src/dmm/asycii.c \
	src/dmm/bm25x.c \
	src/dmm/bm52x.c \
	src/dmm/bm85x.c \
	src/dmm/bm86x.c \
	src/dmm/dtm0660.c \
	src/dmm/eev121gw.c \
	src/dmm/es519xx.c \
	src/dmm/fs9721.c \
	src/dmm/fs9922.c \
	src/dmm/m2110.c \
	src/dmm/metex14.c \
	src/dmm/ms2115b.c \
	src/dmm/ms8250d.c \
	src/dmm/rs9lcd.c \
	src/dmm/ut372.c \
	src/dmm/ut71x.c \
	src/dmm/vc870.c \
	src/dmm/vc96.c

# Hardware (LCR chip parsers)
if NEED_SERIAL
libsigrok_la_SOURCES += \
	src/lcr/es51919.c \
	src/lcr/vc4080.c
endif

# Hardware (Scale protocol parsers)
libsigrok_la_SOURCES += \
	src/scale/kern.c

# Hardware drivers
noinst_LTLIBRARIES = src/libdrivers.la \
	src/libdrivers_head.la src/libdrivers_tail.la

src/libdrivers.o: src/libdrivers.la \
		src/libdrivers_head.la src/libdrivers_tail.la
	$(AM_V_CCLD)$(LINK) src/libdrivers_head.la src/libdrivers.la \
		src/libdrivers_tail.la
src/libdrivers.lo: src/libdrivers.o
	$(AM_V_GEN)echo "# Generated by libtool" > $@
	$(AM_V_at)echo "pic_object='libdrivers.o'" >> $@
	$(AM_V_at)echo "non_pic_object='libdrivers.o'" >> $@

src_libdrivers_head_la_SOURCES = src/driver_list_start.c

src_libdrivers_tail_la_SOURCES = src/driver_list_stop.c

src_libdrivers_la_SOURCES = src/drivers.c

if HW_AGILENT_DMM
src_libdrivers_la_SOURCES += \
	src/hardware/agilent-dmm/protocol.h \
	src/hardware/agilent-dmm/protocol.c \
	src/hardware/agilent-dmm/api.c
endif
if HW_APPA_55II
src_libdrivers_la_SOURCES += \
	src/hardware/appa-55ii/protocol.h \
	src/hardware/appa-55ii/protocol.c \
	src/hardware/appa-55ii/api.c
endif
if HW_ARACHNID_LABS_RE_LOAD_PRO
src_libdrivers_la_SOURCES += \
	src/hardware/arachnid-labs-re-load-pro/protocol.h \
	src/hardware/arachnid-labs-re-load-pro/protocol.c \
	src/hardware/arachnid-labs-re-load-pro/api.c
endif
if HW_ASIX_SIGMA
src_libdrivers_la_SOURCES += \
	src/hardware/asix-sigma/protocol.h \
	src/hardware/asix-sigma/protocol.c \
	src/hardware/asix-sigma/api.c
endif
if HW_ATTEN_PPS3XXX
src_libdrivers_la_SOURCES += \
	src/hardware/atten-pps3xxx/protocol.h \
	src/hardware/atten-pps3xxx/protocol.c \
	src/hardware/atten-pps3xxx/api.c
endif
if HW_BAYLIBRE_ACME
src_libdrivers_la_SOURCES += \
	src/hardware/baylibre-acme/protocol.h \
	src/hardware/baylibre-acme/protocol.c \
	src/hardware/baylibre-acme/api.c \
	src/hardware/baylibre-acme/gpio.h \
	src/hardware/baylibre-acme/gpio.c
endif
if HW_BEAGLELOGIC
src_libdrivers_la_SOURCES += \
	src/hardware/beaglelogic/beaglelogic.h \
	src/hardware/beaglelogic/protocol.h \
	src/hardware/beaglelogic/protocol.c \
	src/hardware/beaglelogic/api.c \
	src/hardware/beaglelogic/beaglelogic_native.c \
	src/hardware/beaglelogic/beaglelogic_tcp.c
endif
if HW_CEM_DT_885X
src_libdrivers_la_SOURCES += \
	src/hardware/cem-dt-885x/protocol.h \
	src/hardware/cem-dt-885x/protocol.c \
	src/hardware/cem-dt-885x/api.c
endif
if HW_CENTER_3XX
src_libdrivers_la_SOURCES += \
	src/hardware/center-3xx/protocol.h \
	src/hardware/center-3xx/protocol.c \
	src/hardware/center-3xx/api.c
endif
if HW_CHRONOVU_LA
src_libdrivers_la_SOURCES += \
	src/hardware/chronovu-la/protocol.h \
	src/hardware/chronovu-la/protocol.c \
	src/hardware/chronovu-la/api.c
endif
if HW_COLEAD_SLM
src_libdrivers_la_SOURCES += \
	src/hardware/colead-slm/protocol.h \
	src/hardware/colead-slm/protocol.c \
	src/hardware/colead-slm/api.c
endif
if HW_CONRAD_DIGI_35_CPU
src_libdrivers_la_SOURCES += \
	src/hardware/conrad-digi-35-cpu/protocol.h \
	src/hardware/conrad-digi-35-cpu/protocol.c \
	src/hardware/conrad-digi-35-cpu/api.c
endif
if HW_DEMO
src_libdrivers_la_SOURCES += \
	src/hardware/demo/protocol.h \
	src/hardware/demo/protocol.c \
	src/hardware/demo/api.c
endif
if HW_DREAMSOURCELAB_DSLOGIC
src_libdrivers_la_SOURCES += \
	src/hardware/dreamsourcelab-dslogic/protocol.h \
	src/hardware/dreamsourcelab-dslogic/protocol.c \
	src/hardware/dreamsourcelab-dslogic/api.c
endif
if HW_FLUKE_45
src_libdrivers_la_SOURCES += \
	src/hardware/fluke-45/protocol.h \
	src/hardware/fluke-45/protocol.c \
	src/hardware/fluke-45/api.c
endif
if HW_FLUKE_DMM
src_libdrivers_la_SOURCES += \
	src/hardware/fluke-dmm/protocol.h \
	src/hardware/fluke-dmm/protocol.c \
	src/hardware/fluke-dmm/api.c
endif
if HW_FTDI_LA
src_libdrivers_la_SOURCES += \
	src/hardware/ftdi-la/protocol.h \
	src/hardware/ftdi-la/protocol.c \
	src/hardware/ftdi-la/api.c
endif
if HW_FX2LAFW
src_libdrivers_la_SOURCES += \
	src/hardware/fx2lafw/protocol.h \
	src/hardware/fx2lafw/protocol.c \
	src/hardware/fx2lafw/api.c
endif
if HW_GMC_MH_1X_2X
src_libdrivers_la_SOURCES += \
	src/hardware/gmc-mh-1x-2x/protocol.h \
	src/hardware/gmc-mh-1x-2x/protocol.c \
	src/hardware/gmc-mh-1x-2x/api.c
endif
if HW_GWINSTEK_GDS_800
src_libdrivers_la_SOURCES += \
	src/hardware/gwinstek-gds-800/protocol.h \
	src/hardware/gwinstek-gds-800/protocol.c \
	src/hardware/gwinstek-gds-800/api.c
endif
if HW_GWINSTEK_GPD
src_libdrivers_la_SOURCES += \
	src/hardware/gwinstek-gpd/protocol.h \
	src/hardware/gwinstek-gpd/protocol.c \
	src/hardware/gwinstek-gpd/api.c
endif
if HW_HAMEG_HMO
src_libdrivers_la_SOURCES += \
	src/hardware/hameg-hmo/protocol.h \
	src/hardware/hameg-hmo/protocol.c \
	src/hardware/hameg-hmo/api.c
endif
if HW_HANTEK_4032L
src_libdrivers_la_SOURCES += \
	src/hardware/hantek-4032l/protocol.h \
	src/hardware/hantek-4032l/protocol.c \
	src/hardware/hantek-4032l/api.c
endif
if HW_HANTEK_6XXX
src_libdrivers_la_SOURCES += \
	src/hardware/hantek-6xxx/protocol.h \
	src/hardware/hantek-6xxx/protocol.c \
	src/hardware/hantek-6xxx/api.c
endif
if HW_HANTEK_DSO
src_libdrivers_la_SOURCES += \
	src/hardware/hantek-dso/protocol.h \
	src/hardware/hantek-dso/protocol.c \
	src/hardware/hantek-dso/api.c
endif
if HW_HP_3457A
src_libdrivers_la_SOURCES += \
	src/hardware/hp-3457a/protocol.h \
	src/hardware/hp-3457a/protocol.c \
	src/hardware/hp-3457a/api.c
endif
if HW_HP_3478A
src_libdrivers_la_SOURCES += \
	src/hardware/hp-3478a/protocol.h \
	src/hardware/hp-3478a/protocol.c \
	src/hardware/hp-3478a/api.c
endif
if HW_HUNG_CHANG_DSO_2100
src_libdrivers_la_SOURCES += \
	src/hardware/hung-chang-dso-2100/protocol.h \
	src/hardware/hung-chang-dso-2100/protocol.c \
	src/hardware/hung-chang-dso-2100/api.c
endif
if HW_IKALOGIC_SCANALOGIC2
src_libdrivers_la_SOURCES += \
	src/hardware/ikalogic-scanalogic2/protocol.h \
	src/hardware/ikalogic-scanalogic2/protocol.c \
	src/hardware/ikalogic-scanalogic2/api.c
endif
if HW_IKALOGIC_SCANAPLUS
src_libdrivers_la_SOURCES += \
	src/hardware/ikalogic-scanaplus/protocol.h \
	src/hardware/ikalogic-scanaplus/protocol.c \
	src/hardware/ikalogic-scanaplus/api.c
endif
if HW_IPDBG_LA
src_libdrivers_la_SOURCES += \
	src/hardware/ipdbg-la/protocol.h \
	src/hardware/ipdbg-la/protocol.c \
	src/hardware/ipdbg-la/api.c
endif
if HW_ITECH_IT8500
src_libdrivers_la_SOURCES += \
	src/hardware/itech-it8500/protocol.h \
	src/hardware/itech-it8500/protocol.c \
	src/hardware/itech-it8500/api.c
endif
if HW_KECHENG_KC_330B
src_libdrivers_la_SOURCES += \
	src/hardware/kecheng-kc-330b/protocol.h \
	src/hardware/kecheng-kc-330b/protocol.c \
	src/hardware/kecheng-kc-330b/api.c
endif
if HW_KERN_SCALE
src_libdrivers_la_SOURCES += \
	src/hardware/kern-scale/protocol.h \
	src/hardware/kern-scale/protocol.c \
	src/hardware/kern-scale/api.c
endif
if HW_KINGST_LA2016
src_libdrivers_la_SOURCES += \
	src/hardware/kingst-la2016/protocol.h \
	src/hardware/kingst-la2016/protocol.c \
	src/hardware/kingst-la2016/api.c
endif
if HW_KORAD_KAXXXXP
src_libdrivers_la_SOURCES += \
	src/hardware/korad-kaxxxxp/protocol.h \
	src/hardware/korad-kaxxxxp/protocol.c \
	src/hardware/korad-kaxxxxp/api.c
endif
if HW_LASCAR_EL_USB
src_libdrivers_la_SOURCES += \
	src/hardware/lascar-el-usb/protocol.h \
	src/hardware/lascar-el-usb/protocol.c \
	src/hardware/lascar-el-usb/api.c
endif
if HW_LECROY_LOGICSTUDIO
src_libdrivers_la_SOURCES += \
	src/hardware/lecroy-logicstudio/protocol.h \
	src/hardware/lecroy-logicstudio/protocol.c \
	src/hardware/lecroy-logicstudio/api.c
endif
if HW_LECROY_XSTREAM
src_libdrivers_la_SOURCES += \
	src/hardware/lecroy-xstream/protocol.h \
	src/hardware/lecroy-xstream/protocol.c \
	src/hardware/lecroy-xstream/api.c
endif
if HW_MANSON_HCS_3XXX
src_libdrivers_la_SOURCES += \
	src/hardware/manson-hcs-3xxx/protocol.h \
	src/hardware/manson-hcs-3xxx/protocol.c \
	src/hardware/manson-hcs-3xxx/api.c
endif
if HW_MASTECH_MS6514
src_libdrivers_la_SOURCES += \
	src/hardware/mastech-ms6514/protocol.h \
	src/hardware/mastech-ms6514/protocol.c \
	src/hardware/mastech-ms6514/api.c
endif
if HW_MAYNUO_M97
src_libdrivers_la_SOURCES += \
	src/hardware/maynuo-m97/protocol.h \
	src/hardware/maynuo-m97/protocol.c \
	src/hardware/maynuo-m97/api.c
endif
if HW_MICROCHIP_PICKIT2
src_libdrivers_la_SOURCES += \
	src/hardware/microchip-pickit2/protocol.h \
	src/hardware/microchip-pickit2/protocol.c \
	src/hardware/microchip-pickit2/api.c
endif
if HW_MIC_985XX
src_libdrivers_la_SOURCES += \
	src/hardware/mic-985xx/protocol.h \
	src/hardware/mic-985xx/protocol.c \
	src/hardware/mic-985xx/api.c
endif
if HW_MOOSHIMETER_DMM
src_libdrivers_la_SOURCES += \
	src/hardware/mooshimeter-dmm/protocol.h \
	src/hardware/mooshimeter-dmm/protocol.c \
	src/hardware/mooshimeter-dmm/api.c
endif
if HW_MOTECH_LPS_30X
src_libdrivers_la_SOURCES += \
	src/hardware/motech-lps-30x/protocol.h \
	src/hardware/motech-lps-30x/protocol.c \
	src/hardware/motech-lps-30x/api.c
endif
if HW_NORMA_DMM
src_libdrivers_la_SOURCES += \
	src/hardware/norma-dmm/protocol.h \
	src/hardware/norma-dmm/protocol.c \
	src/hardware/norma-dmm/api.c
endif
if HW_OPENBENCH_LOGIC_SNIFFER
src_libdrivers_la_SOURCES += \
	src/hardware/openbench-logic-sniffer/protocol.h \
	src/hardware/openbench-logic-sniffer/protocol.c \
	src/hardware/openbench-logic-sniffer/api.c
endif
if HW_PCE_322A
src_libdrivers_la_SOURCES += \
	src/hardware/pce-322a/protocol.h \
	src/hardware/pce-322a/protocol.c \
	src/hardware/pce-322a/api.c
endif
if HW_PIPISTRELLO_OLS
src_libdrivers_la_SOURCES += \
	src/hardware/pipistrello-ols/protocol.h \
	src/hardware/pipistrello-ols/protocol.c \
	src/hardware/pipistrello-ols/api.c
endif
if HW_RDTECH_DPS
src_libdrivers_la_SOURCES += \
	src/hardware/rdtech-dps/protocol.h \
	src/hardware/rdtech-dps/protocol.c \
	src/hardware/rdtech-dps/api.c
endif
if HW_RDTECH_UM
src_libdrivers_la_SOURCES += \
	src/hardware/rdtech-um/protocol.h \
	src/hardware/rdtech-um/protocol.c \
	src/hardware/rdtech-um/api.c
endif
if HW_RDTECH_TC
src_libdrivers_la_SOURCES += \
	src/hardware/rdtech-tc/protocol.h \
	src/hardware/rdtech-tc/protocol.c \
	src/hardware/rdtech-tc/api.c
endif
if HW_RIGOL_DG
src_libdrivers_la_SOURCES += \
	src/hardware/rigol-dg/protocol.h \
	src/hardware/rigol-dg/protocol.c \
	src/hardware/rigol-dg/api.c
endif
if HW_RIGOL_DS
src_libdrivers_la_SOURCES += \
	src/hardware/rigol-ds/protocol.h \
	src/hardware/rigol-ds/protocol.c \
	src/hardware/rigol-ds/api.c
endif
if HW_ROHDE_SCHWARZ_SME_0X
src_libdrivers_la_SOURCES += \
	src/hardware/rohde-schwarz-sme-0x/protocol.h \
	src/hardware/rohde-schwarz-sme-0x/protocol.c \
	src/hardware/rohde-schwarz-sme-0x/api.c
endif
if HW_SALEAE_LOGIC16
src_libdrivers_la_SOURCES += \
	src/hardware/saleae-logic16/protocol.h \
	src/hardware/saleae-logic16/protocol.c \
	src/hardware/saleae-logic16/api.c
endif
if HW_SALEAE_LOGIC_PRO
src_libdrivers_la_SOURCES += \
	src/hardware/saleae-logic-pro/protocol.h \
	src/hardware/saleae-logic-pro/protocol.c \
	src/hardware/saleae-logic-pro/api.c
endif
if HW_SCPI_DMM
src_libdrivers_la_SOURCES += \
	src/hardware/scpi-dmm/protocol.h \
	src/hardware/scpi-dmm/protocol.c \
	src/hardware/scpi-dmm/api.c
endif
if HW_SCPI_PPS
src_libdrivers_la_SOURCES += \
	src/hardware/scpi-pps/protocol.h \
	src/hardware/scpi-pps/protocol.c \
	src/hardware/scpi-pps/profiles.c \
	src/hardware/scpi-pps/api.c
endif
if HW_SERIAL_DMM
src_libdrivers_la_SOURCES += \
	src/hardware/serial-dmm/protocol.h \
	src/hardware/serial-dmm/protocol.c \
	src/hardware/serial-dmm/api.c
endif
if HW_SERIAL_LCR
src_libdrivers_la_SOURCES += \
	src/hardware/serial-lcr/protocol.h \
	src/hardware/serial-lcr/protocol.c \
	src/hardware/serial-lcr/api.c
endif
if HW_SIGLENT_SDS
src_libdrivers_la_SOURCES += \
	src/hardware/siglent-sds/protocol.h \
	src/hardware/siglent-sds/protocol.c \
	src/hardware/siglent-sds/api.c
endif
if HW_SYSCLK_LWLA
src_libdrivers_la_SOURCES += \
	src/hardware/sysclk-lwla/lwla.h \
	src/hardware/sysclk-lwla/lwla.c \
	src/hardware/sysclk-lwla/lwla1016.c \
	src/hardware/sysclk-lwla/lwla1034.c \
	src/hardware/sysclk-lwla/protocol.h \
	src/hardware/sysclk-lwla/protocol.c \
	src/hardware/sysclk-lwla/api.c
endif
if HW_SYSCLK_SLA5032
src_libdrivers_la_SOURCES += \
	src/hardware/sysclk-sla5032/protocol.h \
	src/hardware/sysclk-sla5032/protocol.c \
	src/hardware/sysclk-sla5032/api.c
endif
if HW_TELEINFO
src_libdrivers_la_SOURCES += \
	src/hardware/teleinfo/protocol.h \
	src/hardware/teleinfo/protocol.c \
	src/hardware/teleinfo/api.c
endif
if HW_TESTO
src_libdrivers_la_SOURCES += \
	src/hardware/testo/protocol.h \
	src/hardware/testo/protocol.c \
	src/hardware/testo/api.c
endif
if HW_TONDAJ_SL_814
src_libdrivers_la_SOURCES += \
	src/hardware/tondaj-sl-814/protocol.h \
	src/hardware/tondaj-sl-814/protocol.c \
	src/hardware/tondaj-sl-814/api.c
endif
if HW_UNI_T_DMM
src_libdrivers_la_SOURCES += \
	src/hardware/uni-t-dmm/protocol.h \
	src/hardware/uni-t-dmm/protocol.c \
	src/hardware/uni-t-dmm/api.c
endif
if HW_UNI_T_UT181A
src_libdrivers_la_SOURCES += \
	src/hardware/uni-t-ut181a/protocol.h \
	src/hardware/uni-t-ut181a/protocol.c \
	src/hardware/uni-t-ut181a/api.c
endif
if HW_UNI_T_UT32X
src_libdrivers_la_SOURCES += \
	src/hardware/uni-t-ut32x/protocol.h \
	src/hardware/uni-t-ut32x/protocol.c \
	src/hardware/uni-t-ut32x/api.c
endif
if HW_YOKOGAWA_DLM
src_libdrivers_la_SOURCES += \
	src/hardware/yokogawa-dlm/protocol.h \
	src/hardware/yokogawa-dlm/protocol.c \
	src/hardware/yokogawa-dlm/protocol_wrappers.h \
	src/hardware/yokogawa-dlm/protocol_wrappers.c \
	src/hardware/yokogawa-dlm/api.c
endif
if HW_ZEROPLUS_LOGIC_CUBE
src_libdrivers_la_SOURCES += \
	src/hardware/zeroplus-logic-cube/analyzer.c \
	src/hardware/zeroplus-logic-cube/analyzer.h \
	src/hardware/zeroplus-logic-cube/gl_usb.h \
	src/hardware/zeroplus-logic-cube/gl_usb.c \
	src/hardware/zeroplus-logic-cube/protocol.h \
	src/hardware/zeroplus-logic-cube/protocol.c \
	src/hardware/zeroplus-logic-cube/api.c
endif
if HW_ZKETECH_EBD_USB
src_libdrivers_la_SOURCES += \
	src/hardware/zketech-ebd-usb/protocol.h \
	src/hardware/zketech-ebd-usb/protocol.c \
	src/hardware/zketech-ebd-usb/api.c
endif

libsigrok_la_LIBADD = src/libdrivers.lo $(SR_EXTRA_LIBS) $(LIBSIGROK_LIBS)
libsigrok_la_LDFLAGS = -version-info $(SR_LIB_VERSION) -no-undefined

library_includedir = $(includedir)/libsigrok
library_include_HEADERS = \
	include/libsigrok/libsigrok.h \
	include/libsigrok/proto.h
nodist_library_include_HEADERS = \
	include/libsigrok/version.h
noinst_HEADERS = src/libsigrok-internal.h

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libsigrok.pc

mimeappdir = $(datadir)/mime/packages
mimeapp_DATA = contrib/vnd.sigrok.session.xml

mimeicondir = $(datadir)/icons/hicolor/48x48/mimetypes
mimeicon_DATA = contrib/libsigrok.png

mimeiconscalabledir = $(datadir)/icons/hicolor/scalable/mimetypes
mimeiconscalable_DATA = contrib/libsigrok.svg

EXTRA_DIST = \
	Doxyfile \
	HACKING \
	README.devices \
	bindings/cxx/ConfigKey_methods.cpp \
	bindings/cxx/ConfigKey_methods.hpp \
	bindings/cxx/ConfigKey_methods.i \
	bindings/cxx/Doxyfile \
	bindings/cxx/QuantityFlag_methods.cpp \
	bindings/cxx/QuantityFlag_methods.hpp \
	bindings/cxx/enums.py \
	bindings/python/Doxyfile \
	bindings/python/setup.py \
	bindings/python/sigrok/__init__.py \
	bindings/python/sigrok/core/__init__.py \
	bindings/python/sigrok/core/classes.i \
	bindings/ruby/classes.i \
	bindings/java/Doxyfile \
	bindings/java/org/sigrok/core/classes/classes.i \
	bindings/java/org/sigrok/core/interfaces/DatafeedCallback.java \
	bindings/java/org/sigrok/core/interfaces/LogCallback.java \
	bindings/swig/classes.i \
	bindings/swig/doc.py \
	bindings/swig/templates.i \
	contrib/libsigrok_112x112.png \
	contrib/libsigrok.png \
	contrib/libsigrok.svg \
	contrib/vnd.sigrok.session.xml \
	contrib/60-libsigrok.rules \
	contrib/61-libsigrok-plugdev.rules \
	contrib/61-libsigrok-uaccess.rules

if HAVE_CHECK
TESTS = tests/main
check_PROGRAMS = ${TESTS}
endif

tests_main_SOURCES = \
	include/libsigrok/libsigrok.h \
	tests/lib.c \
	tests/lib.h \
	tests/main.c \
	tests/core.c \
	tests/input_all.c \
	tests/input_binary.c \
	tests/output_all.c \
	tests/transform_all.c \
	tests/session.c \
	tests/strutil.c \
	tests/version.c \
	tests/driver_all.c \
	tests/device.c \
	tests/trigger.c \
	tests/analog.c \
	tests/conv.c

tests_main_LDADD = libsigrok.la $(SR_EXTRA_LIBS) $(TESTS_LIBS)

BUILD_EXTRA =
INSTALL_EXTRA =
UNINSTALL_EXTRA =
CLEAN_EXTRA =

libsigrok-uninstall:
	-rmdir $(DESTDIR)$(includedir)/libsigrok

UNINSTALL_EXTRA += libsigrok-uninstall

if BINDINGS_CXX

lib_LTLIBRARIES += bindings/cxx/libsigrokcxx.la

bindings_cxx_libsigrokcxx_la_SOURCES = bindings/cxx/classes.cpp

bindings_cxx_libsigrokcxx_la_LIBADD = libsigrok.la $(SR_EXTRA_LIBS) $(LIBSIGROKCXX_LIBS) $(SR_EXTRA_CXX_LIBS)
bindings_cxx_libsigrokcxx_la_LDFLAGS = -version-info $(SR_LIB_VERSION) -no-undefined

bindings_cxx_libsigrokcxx_la_includedir = $(includedir)/libsigrokcxx
bindings_cxx_libsigrokcxx_la_include_HEADERS = \
	bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp
nodist_bindings_cxx_libsigrokcxx_la_include_HEADERS = \
	bindings/cxx/include/libsigrokcxx/enums.hpp

pkgconfig_DATA += bindings/cxx/libsigrokcxx.pc

doxy/xml/index.xml: include/libsigrok/libsigrok.h
	$(AM_V_GEN)cd $(srcdir) && SRCDIR=$(abs_srcdir)/ BUILDDIR=$(abs_builddir)/ doxygen Doxyfile 2>/dev/null

bindings/swig/enums.i: bindings/cxx/enums.timestamp
bindings/cxx/enums.cpp: bindings/cxx/enums.timestamp
bindings/cxx/include/libsigrokcxx/enums.hpp: bindings/cxx/enums.timestamp

bindings/cxx/enums.timestamp: $(srcdir)/bindings/cxx/enums.py doxy/xml/index.xml \
		bindings/cxx/ConfigKey_methods.cpp bindings/cxx/QuantityFlag_methods.cpp
	$(AM_V_GEN)$(PYTHON) $(srcdir)/bindings/cxx/enums.py doxy/xml/index.xml
	$(AM_V_at)touch $@

bindings/cxx/classes.lo: bindings/cxx/classes.cpp bindings/cxx/enums.cpp \
		$(library_include_HEADERS) $(nodist_library_include_HEADERS)

cxx-clean:
	rm -rf doxy/
	rm -rf bindings/cxx/doxy/
	rm -f bindings/swig/enums.i
	rm -f bindings/cxx/enums.cpp
	rm -f bindings/cxx/include/libsigrokcxx/enums.hpp
	rm -f bindings/cxx/enums.timestamp

CLEAN_EXTRA += cxx-clean

cxx-uninstall:
	-rmdir $(DESTDIR)$(includedir)/libsigrokcxx

UNINSTALL_EXTRA += cxx-uninstall

endif

CPPXMLDOC = bindings/cxx/doxy/xml/index.xml

$(CPPXMLDOC): bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp \
		bindings/cxx/enums.timestamp
	$(AM_V_GEN)cd $(srcdir)/bindings/cxx && SRCDIR=$(abs_srcdir)/bindings/cxx/ BUILDDIR=$(abs_builddir)/bindings/cxx/ doxygen Doxyfile 2>/dev/null

# Macro definitions to be used by the SWIG parser.
swig_defs = -Dnoexcept= -Dprivate=protected -DG_GNUC_BEGIN_IGNORE_DEPRECATIONS= -DG_GNUC_END_IGNORE_DEPRECATIONS=

if BINDINGS_PYTHON

PDIR = bindings/python
PDOC_START = bindings/python/sigrok/core/doc_start.i
PDOC_END = bindings/python/sigrok/core/doc_end.i

setup_vars = VERSION='$(PACKAGE_VERSION)' CC='$(CXX)' CXX='$(CXX)' CFLAGS='$(CXXFLAGS) $(SR_WXXFLAGS) $(PYSIGROK_CFLAGS)' CXXFLAGS='$(CXXFLAGS) $(SR_WXXFLAGS) $(PYSIGROK_CFLAGS)' LDADD='$(PYSIGROK_LIBS)'
setup_quiet = --quiet
setup_py = $(PYTHON) $(srcdir)/$(PDIR)/setup.py $(setup_vars) $(setup_quiet)

$(PDOC_START): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC)
	$(AM_V_at)test -d $(PDIR)/sigrok/core || $(MKDIR_P) $(PDIR)/sigrok/core
	$(AM_V_GEN)$(PYTHON) $(srcdir)/bindings/swig/doc.py python $(CPPXMLDOC) start > $@

$(PDOC_END): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC)
	$(AM_V_at)test -d $(PDIR)/sigrok/core || $(MKDIR_P) $(PDIR)/sigrok/core
	$(AM_V_GEN)$(PYTHON) $(srcdir)/bindings/swig/doc.py python $(CPPXMLDOC) end > $@

python-build: $(PDIR)/timestamp

$(PDIR)/timestamp: $(PDIR)/sigrok/core/classes.i \
		bindings/swig/classes.i bindings/swig/templates.i \
		bindings/swig/enums.i $(PDOC_START) $(PDOC_END) \
		$(library_include_HEADERS) \
		$(nodist_library_include_HEADERS) \
		$(bindings_cxx_libsigrokcxx_la_include_HEADERS) \
		$(nodist_bindings_cxx_libsigrokcxx_la_include_HEADERS) \
		@ORDER@ bindings/cxx/libsigrokcxx.la
	$(AM_V_at)$(setup_py) clean --all 2>/dev/null
	$(AM_V_GEN)$(setup_py) build_ext --swig "$(SWIG)" --swig-opts '$(swig_defs)' build_py
	$(AM_V_at): >$@

python-install:
	$(AM_V_at)$(MKDIR_P) "$(DESTDIR)$(prefix)" "$(DESTDIR)$(exec_prefix)"
	destdir='$(DESTDIR)'; $(setup_py) install $${destdir:+"--root=$$destdir"} \
		--prefix "$(prefix)" --exec-prefix "$(exec_prefix)"

python-clean:
	-$(AM_V_at)rm -f $(PDIR)/timestamp
	-$(AM_V_at)rm -fr $(PDIR)/doxy
	-$(AM_V_at)$(setup_py) clean --all 2>/dev/null

python-doc:
	$(AM_V_at)cd $(srcdir)/$(PDIR) && SRCDIR="$(abs_srcdir)/$(PDIR)/" BUILDDIR="$(abs_builddir)/$(PDIR)/" doxygen Doxyfile 2>/dev/null

BUILD_EXTRA += python-build
INSTALL_EXTRA += python-install
CLEAN_EXTRA += python-clean

endif

if BINDINGS_RUBY

RDIR = bindings/ruby
RDOC = $(RDIR)/doc.i
RWRAP = $(RDIR)/classes_wrap.cpp
ROBJ = $(RWRAP:.cpp=.o)
REXT = $(RDIR)/sigrok.$(RUBY_DLEXT)

$(RDOC): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC)
	$(AM_V_at)test -d $(RDIR) || $(MKDIR_P) $(RDIR)
	$(AM_V_GEN)$(PYTHON) $(srcdir)/bindings/swig/doc.py ruby $(CPPXMLDOC) > $@

$(RWRAP): $(srcdir)/$(RDIR)/classes.i $(RDOC) \
		bindings/swig/classes.i bindings/swig/templates.i \
		bindings/swig/enums.i
	$(AM_V_GEN)$(SWIG) -ruby -c++ -Ibindings -Ibindings/cxx/include -I$(RDIR) $(local_includes) $(swig_defs) -o $@ $(srcdir)/$(RDIR)/classes.i

$(ROBJ): $(RWRAP) \
		$(library_include_HEADERS) \
		$(nodist_library_include_HEADERS) \
		$(bindings_cxx_libsigrokcxx_la_include_HEADERS) \
		$(nodist_bindings_cxx_libsigrokcxx_la_include_HEADERS)
	$(AM_V_CXX)$(CXX) $(RBSIGROK_CFLAGS) -I. -Iinclude -Ibindings/cxx/include $(local_includes) -fPIC -o $@ -c $(RWRAP)

$(REXT): $(ROBJ) @ORDER@ bindings/cxx/libsigrokcxx.la
	$(AM_V_CXXLD)$(CXX) -shared -o $@ $(ROBJ) -lsigrokcxx -Lbindings/cxx/.libs $(RBSIGROK_LIBS)

ruby-build: $(REXT)

ruby-install: $(REXT)
	$(INSTALL) -d $(DESTDIR)$(prefix)/$(RBSIGROK_EXTDIR)
	$(INSTALL) $(REXT) $(DESTDIR)$(prefix)/$(RBSIGROK_EXTDIR)

ruby-uninstall:
	rm -f $(DESTDIR)$(prefix)/$(RBSIGROK_EXTDIR)/sigrok.$(RUBY_DLEXT)

ruby-clean:
	-$(AM_V_at)rm -fr $(RDIR)/doc
	-$(AM_V_at)rm -f $(REXT) $(ROBJ) $(RWRAP) $(RDOC)

ruby-doc: $(RWRAP)
	$(AM_V_at)yard doc -o $(RDIR)/doc $(RWRAP)

BUILD_EXTRA += ruby-build
INSTALL_EXTRA += ruby-install
UNINSTALL_EXTRA += ruby-uninstall
CLEAN_EXTRA += ruby-clean

endif

if BINDINGS_JAVA

JDIR = bindings/java
JPKG = org/sigrok/core
JCLS = $(JDIR)/$(JPKG)/classes
JINT = $(JDIR)/$(JPKG)/interfaces
JSRC = $(JCLS)/*.java $(srcdir)/$(JINT)/*.java
JSWG = $(JCLS)/classes.i
JDOC = $(JCLS)/doc.i
JCXX = $(JCLS)/classes_wrap.cxx
JLIB = $(JDIR)/libsigrok_java_core_classes.so
JJAR = $(JDIR)/sigrok-core.jar

java_cleanfiles = $(JCXX) $(JCLS)/*.java $(JCLS)/*.class $(JINT)/*.class $(JJAR) $(JLIB)

java-build: $(JJAR) $(JLIB)

$(JDOC): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC)
	$(AM_V_at)test -d $(JCLS) || $(MKDIR_P) $(JCLS)
	$(AM_V_GEN)$(PYTHON) $(srcdir)/bindings/swig/doc.py java $(CPPXMLDOC) > $@

$(JCXX): $(srcdir)/$(JSWG) $(JDOC) bindings/swig/classes.i \
		bindings/swig/templates.i bindings/swig/enums.i \
		$(bindings_cxx_libsigrokcxx_la_include_HEADERS) \
		$(nodist_bindings_cxx_libsigrokcxx_la_include_HEADERS)
	-$(AM_V_at)rm -f $(java_cleanfiles)
	$(AM_V_GEN)$(SWIG) -c++ $(swig_defs) \
		-java -package org.sigrok.core.classes \
		-Ibindings -I$(JCLS) $(local_includes) -I$(srcdir) $(JNI_CPPFLAGS) \
		-outdir $(JCLS) -o $@ $(srcdir)/$(JSWG)

$(JJAR): $(JCXX)
	$(AM_V_GEN)$(JAVAC) -d $(JDIR) $(JSRC)
	$(AM_V_at)jar cf $(JJAR) -C $(JDIR) $(JPKG)

$(JLIB): $(JCXX) \
		$(library_include_HEADERS) $(nodist_library_include_HEADERS) \
		$(bindings_cxx_libsigrokcxx_la_include_HEADERS) \
		$(nodist_bindings_cxx_libsigrokcxx_la_include_HEADERS) \
		@ORDER@ bindings/cxx/libsigrokcxx.la
	$(AM_V_GEN)$(CXXCOMPILE) $(JNI_CPPFLAGS) $(LDFLAGS) -L.libs -Lbindings/cxx/.libs \
		-fno-strict-aliasing -fPIC -shared $(JCLS)/classes_wrap.cxx \
		-lsigrokcxx $(LIBSIGROKCXX_LIBS) $(SR_EXTRA_CXX_LIBS) -o $(JLIB)

java-install:
	$(INSTALL) -d $(DESTDIR)$(libdir)/jni
	$(INSTALL) $(JLIB) $(DESTDIR)$(libdir)/jni
	$(INSTALL) -d $(DESTDIR)$(datadir)/java
	$(INSTALL) $(JJAR) $(DESTDIR)$(datadir)/java

java-uninstall:
	-rm -f $(DESTDIR)$(datadir)/java/sigrok-core.jar
	-rm -f $(DESTDIR)$(libdir)/jni/libsigrok_java_core_classes.so

java-clean:
	-$(AM_V_at)rm -f $(java_cleanfiles) $(JDOC)
	-$(AM_V_at)rm -fr $(JDIR)/doxy

java-doc:
	$(AM_V_at)cd $(srcdir)/$(JDIR) && SRCDIR="$(abs_srcdir)/$(JDIR)/" BUILDDIR="$(abs_builddir)/$(JDIR)/" doxygen Doxyfile

BUILD_EXTRA += java-build
INSTALL_EXTRA += java-install
UNINSTALL_EXTRA += java-uninstall
CLEAN_EXTRA += java-clean

endif

all-local: $(BUILD_EXTRA)
install-exec-local: $(INSTALL_EXTRA)
uninstall-hook: $(UNINSTALL_EXTRA)
clean-local: $(CLEAN_EXTRA)

.PHONY: dist-changelog

dist-hook: dist-changelog

dist-changelog:
	$(AM_V_at)if test ! -d '$(top_srcdir)/.git'; then \
		cp -f '$(top_srcdir)/ChangeLog' "$(top_distdir)/ChangeLog"; \
	elif git -C '$(top_srcdir)' log >.ChangeLog.tmp; then \
		mv -f .ChangeLog.tmp "$(top_distdir)/ChangeLog"; \
	else \
		rm -f .ChangeLog.tmp; exit 1; \
	fi

